<?php

include_once 'Expression.php';
include_once 'ExpressionCollection.php';

/**
 * Represents an expression that creates an array
 * 
 * @package UC_PHPCodeModel
 * @author Uros Calakovic 
 * @example ../Examples/ArrayCreateExpressionExample.php
 */

class ArrayCreateExpression extends Expression
{
    /**
     * ArrayCreateExpression constructor
     * 
     * It makes sense to pass the array initializers to the constructor
     * so that an instance can be created with an existing expression colection.
     * Initializers are omitted if an empty array is created.
     * Initializers can also be added or removed after a new instance is created.
     * 
     * @param ExpressionCollection $Initializers The array initializers
     */
    
    public function __construct(ExpressionCollection $Initializers = null)
    {
        parent::__construct();
        
        $Initializers == null ? 
            $this->Initializers = new ExpressionCollection() :
            $this->set_Initializers($Initializers);
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @param mixed $value The value the field should be set to, usually a collection.
     * @see CodeObject::__set()
     */
    
    public function __set($name, $value)
    {
        parent::__set($name, $value);
        
        if($name == 'Initializers')
        {
            $this->set_Initializers($value);
        }
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @return mixed The field that $name specified, usually a collection
     * @see CodeObject::__get()
     */
    
    public function __get($name)
    {
        $ret = parent::__get($name);
        
        if($ret != null)
        {
            return $ret;
        }
        
        if($name == 'Initializers')
        {
            return $this->get_Initializers();
        }
    }
    
    /**
     * The $Initializers getter method
     * @return ExpressionCollection The array initializers collection 
     */
    
    public function get_Initializers()
    {
        return $this->Initializers;
    }

    /**
     * The $Initializers setter method
     * @param ExpressionCollection $Initializers The array initializers collection
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert ('name') throws PHPUnit_Framework_Error
     */
    
    public function set_Initializers(ExpressionCollection $Initializers)
    {
        $this->Initializers = $Initializers;
    }
    
    /**
     * The array initializers collection
     * @var ExpressionCollection 
     */

    private $Initializers;
}

?>
